/*************************************************************************
    > File Name: util.c
    > Author: liujing
    > Mail: jingliu.cs@gmail.com 
    > Created Time: 2014年10月17日 星期五 20时48分34秒
 ************************************************************************/

#include "globals.h"
#include "util.h"

void printToken(TokenType token,const char* tokenString){ 
	switch(token){ 
		case IF:
		case WHILE:
		case ELSE:
		case RETURN:
		case INT:
		case VOID:
			fprintf(listing,RED "reserved word: %s\n"NONE,tokenString);
			break;
		case ASSIGN: fprintf(listing,"=\n"); break;
		case LT: fprintf(listing,"<\n"); break;
		case LTE: fprintf(listing,"<=\n"); break;
		case GT: fprintf(listing,">\n"); break;
		case GTE: fprintf(listing,">=\n"); break;
		case EQ: fprintf(listing,"==\n"); break;
		case NEQ: fprintf(listing,"!=\n"); break;
		case LPAREN: fprintf(listing,"(\n"); break;
		case RPAREN: fprintf(listing,")\n"); break;
		case SEMI: fprintf(listing,";\n"); break;
		case COMMA: fprintf(listing,",\n"); break;
		case LSQUARE: fprintf(listing,"[\n"); break;
		case RSQUARE: fprintf(listing,"]\n"); break;
		case LBRACE: fprintf(listing,"{\n"); break;
		case RBRACE: fprintf(listing,"}\n"); break;
		case PLUS: fprintf(listing,"+\n"); break;
		case MINUS: fprintf(listing,"-\n"); break;
		case TIMES: fprintf(listing,"*\n"); break;
		case OVER: fprintf(listing,"/\n"); break;
		case ENDFILE: fprintf(listing,"EOF\n"); break;
		case NUM:
			fprintf(listing,BLUE "NUM, val= %s\n"NONE,tokenString);
			break;
		case ID:
			fprintf(listing,YELLOW "ID, name= %s\n"NONE,tokenString);
			break;
		case ERROR:
			fprintf(listing,"ERROR: %s\n",tokenString);
			break;
		default: /* should never happen */
			fprintf(listing,"Unknown token: %d\n",token);
		}
}
